{include file="public/header" /}
<link rel="stylesheet" type="text/css" href="/static/admin/webupload/webuploader.css">
<link rel="stylesheet" type="text/css" href="/static/admin/webupload/style.css">
<style>
.file-item{float: left; position: relative; width: 110px;height: 110px; margin: 0 20px 20px 0; padding: 4px;}
.file-item .info{overflow: hidden;}
.uploader-list{width: 100%; overflow: hidden;}
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑等级</h5>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal" name="edit" id="signupForm" method="post" action="{:url('editPost')}">
                        <input type="hidden" name="id" value="{$level.id}">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">直属店长(及以上级别)总数：</label>
                            <div class="input-group col-sm-4">
                                <input type="text" class="form-control" name="direct_total_number" value="{$level.direct_total_number}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">直属有效店长(及以上级别)总数：</label>
                            <div class="input-group col-sm-4">
                                <input type="text" class="form-control" name="direct_valid_number" value="{$level.direct_valid_number}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">非直属店长(及以上级别)总数：</label>
                            <div class="input-group col-sm-4">
                                <input type="text" class="form-control" name="indirect_total_number" value="{$level.indirect_total_number}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">非直属有效店长(及以上级别)总数：</label>
                            <div class="input-group col-sm-4">
                                <input type="text" class="form-control" name="indirect_valid_number" value="{$level.indirect_valid_number}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">我-最小收益：</label>
                            <div class="input-group col-sm-4">
                                <input type="text" class="form-control" name="min_profit" value="{$level.min_profit}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">我-下级最小收益总和：</label>
                            <div class="input-group col-sm-4">
                                <input type="text" class="form-control" name="direct_min_profit" value="{$level.direct_min_profit}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">团队内超级店长数：</label>
                            <div class="input-group col-sm-4">
                                <input type="text" class="form-control" name="all_second_level_number" value="{$level.all_second_level_number}">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">备注：</label>
                            <div class="input-group col-sm-4">
                                <input type="text" class="form-control" name="remark" value="{$level.remark}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button id="formSubmit" type="submit" class="btn btn-primary"><i class="fa fa-check"></i> 提交</button>&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>
{include file="public/footer" /}
<script type="text/javascript" src="/static/admin/webupload/webuploader.min.js"></script>
<script type="text/javascript">
    var $list = $('#fileList');
    //上传图片,初始化WebUploader
    var uploader = WebUploader.create({
     
        auto: true,// 选完文件后，是否自动上传。   
        swf: '/static/admin/webupload/Uploader.swf',// swf文件路径 
        server: "{:url('Upload/uploadFace')}",// 文件接收服务端。
        duplicate :true,// 重复上传图片，true为可重复false为不可重复
        pick: '#imgPicker',// 选择文件的按钮。可选。

        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/jpg,image/jpeg,image/png'
        },

        'onUploadSuccess': function(file, data, response) {
            $("#data_photo").val(data._raw);
            $("#img_data").attr('src', '/uploads/face/' + data._raw).show();
        }
    });

    uploader.on( 'fileQueued', function( file ) {
        $list.html( '<div id="' + file.id + '" class="item">' +
            '<h4 class="info">' + file.name + '</h4>' +
            '<p class="state">正在上传...</p>' +
        '</div>' );
    });

    // 文件上传成功
    uploader.on( 'uploadSuccess', function( file ) {
        $( '#'+file.id ).find('p.state').text('上传成功！');
    });

    // 文件上传失败，显示上传出错。
    uploader.on( 'uploadError', function( file ) {
        $( '#'+file.id ).find('p.state').text('上传出错!');
    });

    //以下为官方示例
    $().ready(function () {

        // validate signup form on keyup and submit
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#signupForm").validate({
            rules: {
                direct_total_number: {
                    required: true,
                    digits:true
                },
                direct_valid_number: {
                    required: true,
                    digits:true
                },
                indirect_total_number: {
                    required: true,
                    digits:true
                },
                indirect_valid_number: {
                    required: true,
                    digits:true
                },
                min_profit: {
                    required: true,
                    number:true
                },
                direct_min_profit: {
                    required: true,
                    number:true
                },
                all_second_level_number: {
                    required: true,
                    digits:true
                },
                remark: {
                    required: true
                }
            },
            focusCleanup:true,
            submitHandler:function(form){

                $(form).ajaxSubmit({
                    type: 'post',
                    url: "{:url('editPost')}",
                    beforeSend:function() {
                        // 显示loading
                        index2 = layer.load(0, {
                            shade: [0.3,'#fff']
                        });
                        $("#formSubmit").attr('type', 'button')
                    },
                    success: function(data){

                        if (data['code'] != 1) {
                            layer.msg(data.msg,{icon:2,time:1000,shade: 0.1,}, function(index){
                                layer.close(index)
                            });
                            $("#formSubmit").attr('type', 'submit')
                            return false;
                        }

                        layer.msg(data.msg,{icon:1,time:1000,shade: 0.1,}, function(index){
//                            index = parent.layer.getFrameIndex(window.name);
//                            parent.layer.close(index);
//                            parent.location.reload(); // 父页面刷新
                            window.location.href="{:url('index')}"
                        });
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer.msg('error!',{icon:1,time:1000});
                    },
                    complete:function() {
                        // 隐藏loading
                        layer.close(index2);
                    }
                });
            }
        });


    });

</script>
</body>
</html>